<?php
/**
 * UUIDGenerator.php created on 18 mai 08 
 * Author: Rodrigue Le Gall
 *
 * RPortal is an open source web based Content Management System
 * Copyright (C) 2002-2008  Rodrigue Le Gall
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * @category RPortal2
 * @package  RPortal_Core
 * @author   Rodrigue Le Gall <r.legall@rportal.org>
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GPLv2
 * @link     http://pear.rportal.org/RPortal_Core
 */

declare (ENCODING = 'utf-8');

 /**
  * generate a UUID
  * 
  * @category RPortal2
  * @package  RPortal_Core
  * @author   Rodrigue Le Gall <r.legall@rportal.org>
  * @license  http://www.gnu.org/licenses/gpl-2.0.html GPLv2
  * @link     http://pear.rportal.org/RPortal_Core
  */
class UUIDGenerator
{
    /**
     * generate an uuid
     * 
     * @param string $prefix a prefix to add to uuid
     * 
     * @return string an uuid
     */
    public function generateUUID($prefix = "")
    {
            $chars = md5(uniqid(rand()));
            $uuid  = substr($chars, 0, 8) . '-';
            $uuid .= substr($chars, 8, 4) . '-';
            $uuid .= substr($chars, 12, 4) . '-';
            $uuid .= substr($chars, 16, 4) . '-';
            $uuid .= substr($chars, 20, 12);
            return $prefix . $uuid;
    }
}
